﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
/// <summary>
/// 跳跃平台管理器
/// </summary>
public class PlatformManager : SingletonProvider<PlatformManager>
{
    public readonly LinkedList<GameObject> mPlatforms = new LinkedList<GameObject>();
    private string mPlatformPath = "Platform";
    private int mMaxCount = 2;
    /// <summary>
    /// 跳跃平台
    /// </summary>
    public void CreatePlatform(Vector3 pos, Vector3 scale, UnityAction callback)
    {
        PoolManager.GetInstance().GetObject(mPlatformPath, (platform)=>
        {
            platform.transform.position = pos;
            platform.transform.localScale = scale;
            mPlatforms.AddLast(platform);
            if (mPlatforms.Count > mMaxCount)
            {
                PoolManager.GetInstance().PushObject(mPlatformPath, mPlatforms.First.Value);
                mPlatforms.RemoveFirst();
            }
            platform.transform.parent = GameManager.GetInstance().movableObjects;
            if (callback != null)
                callback.Invoke();
        });
    }
    /// <summary>
    /// 清空平台
    /// </summary>
    public void ClearAllPlatform()
    {
        foreach (GameObject platform in mPlatforms)
        {
            PoolManager.GetInstance().PushObject(mPlatformPath, platform);
        }
        mPlatforms.Clear();
    }
}
